package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.base.result.ResponseVo;
import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.core.pojo.entity.Lend;
import com.atguigu.srb.core.pojo.entity.LendItemReturn;
import com.atguigu.srb.core.service.LendItemReturnService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 标的出借回款记录表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-10-11
 */
@RestController
@RequestMapping("api/core/lendItemReturn")
public class ApiLendItemReturnController {

    @Resource
    LendItemReturnService lendItemReturnService;

    @ApiOperation("获取会员回款计划")
    @GetMapping("list/{lendId}")
    public ResponseVo listLendItemReturns(@RequestHeader(value = "token",required = false)String token,
                                          @PathVariable("lendId")Long lendId){
        Long userId = JwtUtils.getUserId(token);
        List<LendItemReturn> lendItemReturns = lendItemReturnService.list(Wrappers.lambdaQuery(LendItemReturn.class)
                .eq(LendItemReturn::getLendId, lendId)
                .eq(LendItemReturn::getInvestUserId, userId)
                //先使用LendItemId升序排序， 如果LendItemId相同时使用CurrentPeriod排序
                .orderByAsc(LendItemReturn::getLendItemId, LendItemReturn::getCurrentPeriod));

        return ResponseVo.ok().data("items",lendItemReturns);
    }

}

